    

    var api = api || {};

    api.columnsAll = {
    	//enter(报名表) _ 1(应用appid)
        'enter':{
            "title":"报名", //应用名
            "type": "enter" ,  // enter 报名   form 自定义表单
            "appid":1  ,//
            //coustomerid (组织者ID) 、compid （比赛id） 、 compsubid（分类id 子比赛） appid （应用id ）  

            "columns":[	{"name":"id","display":"ID","hide":true, "db":{'type':'enter|from' , 'appid': 1 } },
            		 	{"name":"name","display":"\u59d3\u540d","render":"function(item,index){return showInfo(item,index);}"  ,  "db":{'type':'enter|from' , 'appid': 1 } },
            		 	{"name":"mobile","display":"\u624b\u673a\u53f7"  ,  "db":{'type':'enter|from' , 'appid': 1 } },
            		 	{"name":"createtime","display":"\u62a5\u540d\u65f6\u95f4","type":"date"  ,  "db":{'type':'enter|from' , 'appid': 1 } },

            		 	{"name":"enter_263","display":"\u6027\u522b" ,  "db":{'type':'enter|from' , 'appid': 1 }},
            		 	{"name":"enter_264","display":"\u5b66\u53f7" ,  "db":{'type':'enter|from' , 'appid': 1 }},
            		 	{"name":"enter_265","display":"\u5b66\u9662" ,  "db":{'type':'enter|from' , 'appid': 1 }},
            		 	{"name":"enter_266","display":"\u4e13\u4e1a" ,  "db":{'type':'enter|from' , 'appid': 1 }},
            		 	
            		 	
            		 ]
        },
        //自定义表单
        'form_888':{
            "title":"自定义表单888",
            "type": "form" ,  // enter 报名   form 自定义表单
            "appid":888  ,//
            //coustomerid (组织者ID) 、compid （比赛id） 、 compsubid（分类id 子比赛） appid （应用id ） 
            "columns":[
			    		{"name":"form_263","display":"\u6027\u522b"},
            		 	{"name":"form_264","display":"\u5b66\u53f7"},
            		 	{"name":"form_265","display":"\u5b66\u9662"},

            ]
        },

        'form_999':{
            "title":"自定义表单999",
            "type": "form" ,  // enter 报名   form 自定义表单
            "appid":999  ,//
            //coustomerid (组织者ID) 、compid （比赛id） 、 compsubid（分类id 子比赛） appid （应用id ） 
            "columns":[
			    {"display":"测试1","name":"name","type":"text","hide":false,"width":200,"allowEdit":true},
			    {"display":"测试2","name":"name","type":"text","hide":false,"width":200,"allowEdit":true},
            ]
        },

        'admin':{
            "title":"管理员自定义字段",
            "type": "admin" ,  // enter 报名   form 自定义表单
            "appid":1  ,//
            //coustomerid (组织者ID) 、compid （比赛id） 、 compsubid（分类id 子比赛） appid （应用id ） 
            "columns":[
			    //{"display":"测试1","name":"name","type":"text","hide":false,"width":200,"allowEdit":true},
			    //{"display":"测试2","name":"name","type":"text","hide":false,"width":200,"allowEdit":true},


            ]
        },



    };
	
	api.columnsAll = {
		"enter": {
			"title": "报名",
			"type": "enter",//没用
			"customerid": "38",//没用
			"compid": "52",//没用
			"compsubid": "0",//没用
			"appid": "44",//没用
			"columns": [
				{
					"name": "enter_261",
					"fieldtype": "LinkName",
					"display": "姓名",
					"db": {
						"type": "enter",
						"fieldid": "261",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_262",
					"fieldtype": "LinkPhone",
					"display": "手机号",
					"db": {
						"type": "enter",
						"fieldid": "262",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_263",
					"fieldtype": "Radio",
					"display": "性别",
					"db": {
						"type": "enter",
						"fieldid": "263",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_264",
					"fieldtype": "TextField",
					"display": "学号",
					"db": {
						"type": "enter",
						"fieldid": "264",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_265",
					"fieldtype": "Select",
					"display": "学院",
					"db": {
						"type": "enter",
						"fieldid": "265",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_266",
					"fieldtype": "TextField",
					"display": "专业",
					"db": {
						"type": "enter",
						"fieldid": "266",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_276",
					"fieldtype": "Select",
					"display": "年级",
					"db": {
						"type": "enter",
						"fieldid": "276",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_268",
					"fieldtype": "TextField",
					"display": "项目名称",
					"db": {
						"type": "enter",
						"fieldid": "268",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_269",
					"fieldtype": "Select",
					"display": "类别",
					"db": {
						"type": "enter",
						"fieldid": "269",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_270",
					"fieldtype": "TextArea",
					"display": "项目描述",
					"db": {
						"type": "enter",
						"fieldid": "270",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_272",
					"fieldtype": "TextField",
					"display": "指导教师姓名",
					"db": {
						"type": "enter",
						"fieldid": "272",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_273",
					"fieldtype": "Select",
					"display": "指导教师所在学院",
					"db": {
						"type": "enter",
						"fieldid": "273",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_274",
					"fieldtype": "TextField",
					"display": "指导教师职称",
					"db": {
						"type": "enter",
						"fieldid": "274",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				},
				{
					"name": "enter_275",
					"fieldtype": "TextField",
					"display": "指导教师联系方式",
					"db": {
						"type": "enter",
						"fieldid": "275",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "44"
					}
				}
			]
		},
		"form_49": {
			"title": "上传计划书",
			"type": "form",
			"customerid": "38",
			"compid": "52",
			"compsubid": "0",
			"appid": "49",
			"columns": [
				{
					"name": "form_15",
					"fieldtype": "UploadFile",
					"display": "上传计划书",
					"db": {
						"type": "form",
						"fieldid": "15",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "49"
					}
				}
			]
		},
		"form_284": {
			"title": "上传PPT",
			"type": "form",
			"customerid": "38",
			"compid": "52",
			"compsubid": "0",
			"appid": "284",
			"columns": [
				{
					"name": "form_137",
					"fieldtype": "UploadFile",
					"display": "上传PPT",
					"db": {
						"type": "form",
						"fieldid": "137",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "284"
					}
				}
			]
		},
		//admin格式
		"admin": {
			"title": "管理员自定义字段",
			"type": "admin",
			//"customerid": "38",
			//"compid": "52",
			//"compsubid": "0",
			//"appid": "284",
			"columns": [
               // {"display":"测试1","name":"name","type":"text",allowEdit":true ,"db":{}},
               // {"display":"测试2","name":"name","type":"text",allowEdit":true ,"db":{}},
            ]
		}
	}


    
    //表格 显示列 配置json
    api.columns = [
    	
				{
					"name": "form_137",	"fieldtype": "UploadFile","display": "上传PPT","db": {
						"type": "form",
						"fieldid": "137",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "284"
					}
				},
				{
					"name": "form_15",
					"fieldtype": "UploadFile",
					"display": "上传计划书",
					"db": {
						"type": "form",
						"fieldid": "15",
						"customerid": "38",
						"compid": "52",
						"compsubid": "0",
						"appid": "49"
					}
				}

    ];

    //表格 内容json
    api.mlist =  'mlist.json';

    //console.log(columns);
    $(function () {
        $grid = $('#dataList').bcGrid({
            columns: api.columns,
            checkbox: true,
            params: {labelid: 'no', compid: '52 ',compsubid:'0',flowid:'50',appid:'44'},
            csrf: 'UGE5ckVRRmg4AmMbIBItAj4wcCIzBDc7ZxRvIXA0LwMKG1tCd2hyMQ==',
            usePager: true,
            pageSize: 'all',
            pageSizeOptions: [10, 20, 30, 40, 50, 'all'],
            pageElement: '#dataPage',
            onCheckClick: checkRows,
            onCheckAllClick: checkRows,
            onLoadedData: function () {

                var p = this;
                $('.link_tip').html('共' + $grid.getTotal() + '条');
//lrxin edit
                $('#dataList tr').find('td:gt(0)').on('dblclick',function (e) {
                        var rowIndex = $(this).closest('tr').data('rowIndex');
                        var rowData = p.data[p.rows][rowIndex];
                        if( e.target ==  this ){
                            alert( rowData.id );
                            //showInfoBox(rowData.id);

                        };
                       //console.log( 'rowIndex:',rowIndex, 'rowData:',  rowData );
                        
                });

                     
            },
            onInit:function(g){
                btn_add_field(g);  
            },
            url:api.mlist ,  //读取表格内容json
            editSaveUrl: 'editSaveUrl.php'


            

        });
        function btn_add_field(g){
            var g = g || $grid , p = g.options ;
            $btn = $('<button type="button" class="btn btn_add_admin_field" id="btn_add_admin_field"> + </button>').prependTo(g.gridWrap);
            $btn.on('mouseenter' ,function(){
                $btn.html('添加自定义字段');
            }).on('mouseleave' , function(){
                $btn.html('+');
            }).on("click",function(){
                sahdeope('__popu_add_field'); //关闭 对话框
            })
        };







        BC.readyKeyEnter("#name,#mobile", function () {
            $('.search_btn').trigger('click');
        });

        //给移动到下拉框 添加最有一个选项 未设置标签
        $("#moveTag option:last").after('<option value="0">未设置标签</option>');
        //移动
        $("#moveTag").on('change', function () {
            var self = $(this);
            if (self.val() == "") {
            }
            else {
                var moveRows = $grid.getCheckedRows();
                if (moveRows.length > 0) {
                    var moveIds = [];
                    $.each(moveRows, function () {
                        moveIds.push(this.id);
                    });
                    BC.ajax({
                        url: 'movetag',
                        data: {"ids": moveIds.join(','), "tagid": self.val(), "_csrf": $("#_csrf").val()},
                        success: function (message, data) {
                            BC.showSuccess('移动成功！', function () {
                                BC.reloadPage();
                            });
                        },
                        fail: function (message) {
                            BC.showError(message);
                        }
                    });
                }
                else {
                    BC.tipWarning("请选择所要移动的数据！");

                }
            }
        });

        //联系人下拉 -----
        $('.nav3_allLinkman').bind('click', function () {
            var $nav3down = $('.nav3_allLinkman_down');
            var disnone = $nav3down.css('display');
            if (disnone == 'none') {
                $nav3down.slideDown(300);
                $(this).children('a').removeClass('icon-caret-down').addClass('icon-caret-up');
            } else {
                $nav3down.slideUp(300);
                $(this).children('a').removeClass('icon-caret-up').addClass('icon-caret-down');
            }
        });

        //标签设置
        labelset();

        //添加标签 按钮
        $('.plus-circle').click(function () {
            $('#labelName').data('id', 0); //
            $('#labelName').val('');
            sahdeope('addlabel'); //关闭 对话框
        });

        //发送短信
        $('#sendSMS').click(function () {
            sendSms();
        });
        //发送短信 submint
        $('#sendSmsSubmit').click(function () {
            BC.confirm("您确认群发以上内容短信？", function () {
                sendSmsSubmit();
            });

        });

        //关闭按钮和取消按钮
        $('.close_shade').click(function () {
            var close = $(this).attr('close');
            sahdeope(close);
            return false;
        });

        //保存按钮  添加新标签
        $('.save_label').click(function () {
            var $inputtext = $('#labelName');
            var label = $inputtext.val();
            var close = $(this).attr('close');
            if (label == '') {
                BC.tipError('标签名称不能为空');
                return;
            }
            if (label.length > 12) {
                BC.tipError('标签名称不能超过12个字符');
                return;
            }
            var id = $inputtext.data('id');
            BC.ajax({
                url: 'savetag',
                data: {"id": id, "name": label, "_csrf": $("#_csrf").val(),"compid":52,"compsubid":0},
                success: function (message, data) {
                    BC.showSuccess(message, function () {
                        if (id == "0") {
                            var labelLi = '<li class="label_de"><a class="label_de_word" href="javascript:void(0);" data-url="/contacts/main/?tag='+data+'"   data-id="'+data+'"><span id="label_' + data + '">'+ label + '</span>';
                            labelLi = labelLi + "(<span  id=\"lableCount_" + data + "\">0</span>)<i class='set_btn del_icon'></i><i class='set_btn set_icon'></i></a></li>";
                            $('.nav3_label_list li:last-child').before(labelLi);//插入标签
                            //下拉菜单处理
                            $("#moveTag option:last").before('<option value="'+data+'">'+label+'</option>');
                            labelset();//重新绑定标签划过设置
                        }
                        else {
                            $("#moveTag option[value='"+id+"']").html(label);
                            $("#label_" + data).html(label);
                        }
                    });
                },
                fail: function (message) {
                    BC.showError(message);
                },
                complete: function () {
                    $inputtext.attr('value', '');//清空textarea
                    $inputtext.data('id', '');
                    sahdeope(close);
                }
            });
        });

        $('#save_add_field').on('click',function(){
            var $input = $('#add_field_name');
            var text = $input.val();
            var close = $(this).attr('close');
            if( text == '' ){
                BC.tipError('自定义字段名称不能为空');
                return;
            }
            if ( text.length > 5 ) {
                BC.tipError('自定义字段名称不能超过5个字');
                return;
            }

            BC.ajax({
                url: 'save_add_field.php',
                data: {"name": text, "_csrf": $("#_csrf").val(),"compid":52,"compsubid":0},
                success: function (message, data) {

                    //var column = {"display":text,"name":data.name,"type":"text","allowEdit":true} ;
                    //var column = {"display":text,"name":data.name,"type":"text","allowEdit":true , "db":{} } ;
                    var column = data;
                    save_add_field_ajax_callback( column );
					BC.showSuccess(message);
                },
                fail: function (message) {
                    BC.showError(message);
                },
                complete: function () {
                    $input.attr('value', '');//清空
                    sahdeope(close);
                }
            });
        });
        function save_add_field_ajax_callback( column ){
            var g = $grid; 
            //g.options.columns.push( {"display":"测试2","name":"name","type":"text","hide":false,"width":200,"allowEdit":true} );
            g.options.columns.push(column);
            var a = api.columnsAll['admin'].columns.push(column);//
            GD.btn_reset();//重构 字段选择

            g._setHead();
            g._setGridContent();
            g._displayData();
            $( 'th:last' ,g.gridHead).find('.bcgrid_head_btn_edit').trigger('click');
        }


        //
        $("#smsContent,#smsSign").on('keyup', function () {
            var count = $("#toName").data('count');
            var smscount = calcCount(count, $("#smsSign").val(), $("#smsContent").val());
            $("#smsCount").html(smscount);
        });
    });
    //----------------------------------------------
    //----------------------------------------------
    //----------------------------------------------
    function  showInfo(item,rowindex) {
        return str = "<a  data='" + item.id + "' >"+item.name+"</a>";
    }

    function showInfoBox(id,index) {
        BC.ajax({
            url: '/main/flow/info',
            data: {compid: 52,flowid:50,compsubid:0,entermemberid:id, _csrf: "" + $grid.get('csrf') + ""},
            loadingTip: '数据读取中...',
            dataType:'html',
            success: function (message, data) {
                $(".mes_box_body").html(message);
                showBox();
            },
            fail: function (message) {
                BC.showError(message);
            }
        });
    }
    function showBox() {
        $(".mes_box_body").show();
        $(".body_bg").show();
        $(".niceScrollInfo").niceScroll({
            touchbehavior:false,
            cursorcolor:"#666",
            cursoropacitymax:1,
            cursorwidth:5,
            cursorborder:"none",
            cursorborderradius:"4px",
            background:"#999",
            //autohidemode:false
        });
        $(".mes_box_body").find(".del").click(function () {
            $(this).parents(".mes_box_body").hide();
            $(this).parents(".mes_box_body").siblings(".body_bg").hide();
            $(".niceScrollInfo").getNiceScroll().hide();
        });
        $(".header").children(".heading").click(function(){
            $(this).addClass("on").siblings().removeClass("on");
            var id = $(this).attr("for");
            $("#"+id).show().siblings().hide();
            $(".headerw").show();
            $(".niceScrollInfo").getNiceScroll().resize();
        });

        $(".leftBox").find("li").click(function(){
            $(this).addClass("on").siblings().removeClass("on");
            var id = $(this).attr("for");
            $("#"+id).show().siblings().hide();
            $(this).parents(".leftBox").show();
            $(".niceScrollInfo").getNiceScroll().resize();
        });
    }
    //弹出层
    function sahdeope(showclass) {
        $('.shade_boxW').toggle();
        $('.shade_boxW').find('.' + showclass).toggle();
    }
    //获取 修改 删除
    function getOperate(item, rowindex) {
        return str = "<a href=\"/enter/main/index?compid=52&compsubid=0&mid=" + item.id + "\" title=\"修改\">修改</a>&nbsp;|&nbsp;<a href=\"javascript:deleteRow(" + item.id + "," + rowindex + ")\" title=\"删除\">删除</a>";
    }

    function checkRows() {
        if ($grid.getCheckedRows().length > 0) {
            $('.Framework-operate .fll input').removeAttr("disabled");
            $('.Framework-operate .fll select').removeAttr("disabled");
        }
        else {
            $('.Framework-operate .fll input').attr("disabled", "disabled");
            $('.Framework-operate .fll select').attr("disabled", "disabled");
        }
    }

    //标签 被点击 效果
    function labelset() {
        //
        $('.label_de').mouseenter(function () {
            $(this).addClass('onhover').siblings().removeClass('onhover');
        }).mouseleave(function () {
            $(this).removeClass('onhover')
        });
        //
        $('.label_de a').on('click',function(){
            BC.redirect($(this).data('url'));
        });
        //
        $(".nav3_label_list .del_icon").on('click', function (e) {
            e.stopPropagation();//阻止冒泡
            var id = $(this).parent().data('id');
            deleteTag(id);//删除标签

        });
        //
        $(".nav3_label_list .set_icon").on('click', function (e) {
            e.stopPropagation();//阻止冒泡
            var id = $(this).parent().data('id');
            var name = $("#label_" + id).html();
            $('#labelName').data('id', id);
            $('#labelName').val(name);
            sahdeope('addlabel');
        });
    }
    //删除标签
    function deleteTag(id) {
        BC.confirm("您确认删除此标签？<br/>删除后,此标签下的联系人将移动到未设置标签下。", function () {
            var count = $("#labelCount_" + id).html();
            BC.ajax({
                url: 'deltag',
                data: {id: id, _csrf: $("#_csrf").val()},
                loadingTip: '数据删除中...',
                success: function (message, data) {
                    BC.showSuccess(message, function () {
                        //$grid.deleteRow(index);
                        $(".label_de_word[data-id='" + id + "']").parent().remove();
                        $("#labelCount_noSet").html(parseInt($("#labelCount_noSet").html()) + parseInt(count));
                    });
                },
                fail: function (message) {
                    BC.showError(message);
                }
            });
        });
    }

    function deleteRow(id, index) {
        BC.confirm("您确认要删除此联系人？", function () {
            BC.ajax({
                url: 'del',
                data: {id: id, _csrf: "" + $grid.get('csrf') + ""},
                loadingTip: '数据删除中...',
                success: function (message, data) {
                    BC.showSuccess(message, function () {
                        $grid.deleteRow(index);
                    });
                },
                fail: function (message) {
                    BC.showError(message);
                }
            });
        });
    }

    function sendSms() {
        var smsPanel = $(".send_msg");
        var selectRows = $grid.getCheckedRows();
        if (selectRows.length == 0) {
            BC.tipError('请先选择联系人！');
            return;
        }
        var toNames = [], toMobiles = [];

        $.each(selectRows, function (index, item) {
            toMobiles.push(this.mobile);
            if (index <= 9) {
                toNames.push(this.name);
            }
        });
        toNames = toNames.join(',');
        if (toMobiles.length > 10) {
            toNames += '等';
        }
        toNames += " 共" + toMobiles.length + "人";
        $("#toName").val(toNames);
        $("#toName").data('mobiles', toMobiles.join(','));
        $("#toName").data('count', toMobiles.length);

        var smsCount = calcCount(toMobiles.length, $("#smsSign").val(), $('#smsContent').val());
        $("#smsCount").html(smsCount);
        sahdeope('send_msg');

    }

    function sendSmsSubmit() {
        var mobiles = $("#toName").data('mobiles');
        if (mobiles == "") {
            BC.tipError("请先选择联系人！");
            return;
        }
        var sign = $.trim($("#smsSign").val());
        if (!checkSign(sign)) {
            return;
        }
        var content = $.trim($('#smsContent').val());
        if (content == "") {
            BC.tipError("请先填写短信内容！");
            return;
        }
        var count = $("#toName").data('count');
        var smscount = calcCount(count, sign, content);
        if (parseInt(smscount) > parseInt($("#smsavailable").val())) {
            BC.confirm("您本次群发需要消耗短信：" + smscount + "条，账户余额：" + $("#smsavailable").val() + "条。<br/>余额不足，是否立即充值？", function () {
                BC.redirect('/contacts/sms/buy');
            });
            return;
        }
        else {
            BC.ajax({
                url: '/contacts/main/sendsms',
                data: {mobiles: mobiles, _csrf: $("#_csrf").val(), sign: sign, content: content},
                success: function (message, data) {
                    BC.showSuccess(message, function () {
                        $("#smsavailable").val(parseInt($("#smsavailable").val()) - smscount);

                    });
                },
                fail: function (message) {
                    BC.showError(message);
                },
                complete:function () {
                    sahdeope(close);
                }
            });
        }
    }

    function checkSign(val) {
        var zreg = /^[\u4e00-\u9fa5a-zA-Z]+$/;
        if (val == "") {
            BC.tipWarning("请输入短信签名！");
            return false;
        }
        if (val.length > 8) {
            BC.tipWarning("短信签名过长！请适当精简！");
            return false;
        }
        if (zreg.test(val)) {
            return true;
        }
        else {
            BC.tipWarning("短信签名内容只能为汉字或字母！");
            return false;
        }

    }

    function calcCount(plength, sign, content) {
        sign = '【' + $.trim(sign) + '】';
        content = $.trim(content);
        console.log('signLen:' + sign.length + '   clen:' + content.length);
        var totalLength = sign.length + content.length;
        var count = 0;
        if (totalLength == 0) {
            count = 0;
        } else if (totalLength <= 70) {
            count = parseInt(plength);
        } else {
            count = parseInt(plength) * Math.ceil(totalLength / 67);
        }
        //
        if (parseInt(count) > parseInt($("#smsavailable").val())) {
            $('#msgTip').show();
        }
        else {
            $('#msgTip').hide();
        }
        return count;

    }

    //---------------


    //------------ edit by lrxin -----------------
    (function($) {

        var gd = {};

        gd.columns = api.columns;
        gd.columnsAll =  api.columnsAll ;

        //打开 关闭 窗口
        gd.open = function(){
            sahdeope('__set_field');
        }
        gd.close = function(){
            sahdeope('__set_field');
        }

        //字段排序列表
        gd.$sortList =  $( "#sf-sort-list" );
        //字段列表 （checkbox）
        gd.$checkboxList =  $( "#sf-checkbox-list" );

        gd.displayteam = function(){

            return '666';
        }


//比较两个对象是否相等 http://www.jb51.net/article/60826.htm
        gd.isEq = gd.isEqual = function( x, y ) {
            // If both x and y are null or undefined and exactly the same
            if ( x === y ) {
                return true;
            }

            // If they are not strictly equal, they both need to be Objects
            if ( ! ( x instanceof Object ) || ! ( y instanceof Object ) ) {
                return false;
            }

            //They must have the exact same prototype chain,the closest we can do is
            //test the constructor.
            if ( x.constructor !== y.constructor ) {
                return false;
            }

            for ( var p in x ) {
                //Inherited properties were tested using x.constructor === y.constructor
                if ( x.hasOwnProperty( p ) ) {
                    // Allows comparing x[ p ] and y[ p ] when set to undefined
                    if ( ! y.hasOwnProperty( p ) ) {
                        return false;
                    }

                    // If they have the same strict value or identity then they are equal
                    if ( x[ p ] === y[ p ] ) {
                        continue;
                    }

                    // Numbers, Strings, Functions, Booleans must be strictly equal
                    if ( typeof( x[ p ] ) !== "object" ) {
                        return false;
                    }

                    // Objects and Arrays must be tested recursively
                    if ( ! Object.equals( x[ p ], y[ p ] ) ) {
                        return false;
                    }
                }
            }

            for ( p in y ) {
                // allows x[ p ] to be set to undefined
                if ( y.hasOwnProperty( p ) && ! x.hasOwnProperty( p ) ) {
                    return false;
                }
            }
            return true;
        };
        gd.cmp = function( x , y){
            return x.name == y.name ;
        }
        //创建 字段列表
        gd.makeCheckboxList = function(){
            //return false;
            gd.$checkboxList.empty();

            $.each(gd.columnsAll , function(i,v){
                //console.log( i ,v , v.title, v.type , v.columns);
                var $dl = $('<dl></dl>');
                var $dt = $('<dt></dt>').append('<strong>'+v.title+'</stong>');
                $dl.append( $dt );

                $.each(v.columns, function( ii, vv){
                    //console.log(vv ); 
                    var $dd = $('<dd><label><input class="checkbox" type="checkbox"> ' + vv.display + '</label></dd>');
                    $dd.find('input:checkbox').data('col',vv);

                    $dl.append( $dd );
                });
                gd.$checkboxList.append($dl);
            });
            
        }

        //向 排序列表 末尾 追加 一条记录
        gd._sortAddRow = function( j ){

            var row = $('<li>'+ j.display +'</li>');
            row.data('col',j);
            gd.$sortList.append(row);
        }
        //创建排序 列表
        gd.makeSortList = function(){
            gd.$sortList.empty();
            $.each(gd.columns , function(i,v){

                gd._sortAddRow(v);

            })
        };


        //设置 字段列表 谁被选中
        gd.setCheckboxListClecked = function(){

            $.each( gd.$checkboxList.find('input:checkbox') , function(i,v){
                //console.log(i,v, $(v).data('col'));
                var $cleckbox  = $(v);
                var col = $cleckbox.data('col');
                var isCleck = false;
                $.each(gd.columns , function(i,v){
                    if( gd.cmp(v , col )  ){
                        //如果存在 跳出循环
                        isCleck = true;
                        return false;//break;
                    };
                });
                if(isCleck){
                    $cleckbox.prop("checked",true);
                }
            })
        }

        //创建 绑定实践
        gd.bind = function(){
            //拖动排序
            gd.$sortList.sortable();
            //因为他们要拖动，所以尽量设置他们的文字不能选择。
            gd.$sortList.disableSelection();
            //修改 编辑 中.....
            //点击字段列表 添加 或 删除 字段排序列表 字段
            gd.$checkboxList.on( 'change', 'input:checkbox' , function(){
                var $t = $(this);
                if( $t.prop("checked")  ){
                    //添加
                    gd._sortAddRow( $t.data('col') );
                }else{
                    //删除
                    $.each( gd.$sortList.find('li') , function(i,v){
                        var $li = $(this);
                        var col = $li.data('col');
                        if( gd.cmp( col , $t.data('col') )  ){
                            $li.remove();
                        };
                    });
                }
            });
        };



        //获取当前排序列表
        gd._getSortList_columns = function(){
            var columns = [];
            $.each( gd.$sortList.find('li') , function(i,v){
                var li = $(this);
                columns.push( li.data('col') );
            });
            return columns;
        };
        //点击保存 提交
        gd.btn_submit = function(){
            //获取当前排序列表
            gd.columns  = gd._getSortList_columns();

            //重新设置 grid 的 列属性
            $grid.set( {
                columns: gd.columns
            } );
            //重新设置 数据源
            //
            //console.log(BC.buildSearchData('.Framework-operate'));
            var params = BC.buildSearchData('.Framework-operate');
            $grid.set({params: {labelid: 'no', compid: '52 ',compsubid:'0',flowid:'50',appid:'44'} });
            $grid.refresh(true); //整体刷新

            //关闭对话框
            gd.close();
        }

        //初始化
        gd.init = function(){
            //创建 字段列表
            gd.makeCheckboxList();
            //创建 排序列表
            gd.makeSortList();
            //设置 字段列表 选中项
            gd.setCheckboxListClecked();
            //绑定事件
            gd.bind();

        }
        //重置
        gd.btn_reset = function(){
            //创建 字段列表
            gd.makeCheckboxList();
            //创建 排序列表
            gd.makeSortList();
            //设置 字段列表 选中项
            gd.setCheckboxListClecked();
        }

        window["GD"] = gd;

        //当文件加载完成 再执行。。。
        $(function(){
            gd.init();
        });
    })(jQuery);